package ngames.com.sushitv.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import ngames.com.sushitv.R;

public class MainActivity extends AppCompatActivity {
    FragmentManager fragmentManager;

    ImageView homeImage;
    ImageView subscriptImage;
    ImageView activityImage;
    ImageView searchImage;
    ImageView accountImage;

    TextView homeText;
    TextView subscriptText;
    TextView activityText;
    TextView searchText;
    TextView accountText;

    LinearLayout homeLayout;
    LinearLayout subscriptLayout;
    LinearLayout activityLayout;
    LinearLayout searchLayout;
    LinearLayout accountLayout;

    List<Fragment> fragments = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fragmentManager = getSupportFragmentManager();

        homeLayout = (LinearLayout) findViewById(R.id.homeLayout);
        subscriptLayout = (LinearLayout) findViewById(R.id.subscriptLayout);
        activityLayout = (LinearLayout) findViewById(R.id.activityLayout);
        searchLayout = (LinearLayout) findViewById(R.id.searchLayout);
        accountLayout = (LinearLayout) findViewById(R.id.accountLayout);

        homeImage = (ImageView) findViewById(R.id.homeImage);
        subscriptImage = (ImageView) findViewById(R.id.subscriptImage);
        activityImage = (ImageView) findViewById(R.id.activityImage);
        searchImage = (ImageView) findViewById(R.id.searchImage);
        accountImage = (ImageView) findViewById(R.id.accountImage);

        homeText = (TextView) findViewById(R.id.homeText);
        subscriptText = (TextView) findViewById(R.id.subscriptText);
        activityText = (TextView) findViewById(R.id.activityText);
        searchText = (TextView) findViewById(R.id.searchText);
        accountText = (TextView) findViewById(R.id.accountText);

        fragments.add(fragmentManager.findFragmentById(R.id.homeFragment));
        fragments.add(fragmentManager.findFragmentById(R.id.subscriptFragment));
        fragments.add(fragmentManager.findFragmentById(R.id.activityFragment));
        fragments.add(fragmentManager.findFragmentById(R.id.searchFragment));
        fragments.add(fragmentManager.findFragmentById(R.id.accountFragment));

        fragmentManager.beginTransaction().hide(fragments.get(1)).hide(fragments.get(2)).hide(fragments.get(3)).hide(fragments.get(4)).commit();
        homeText.setTextColor(getResources().getColor(R.color.selected));

        homeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragmentManager.beginTransaction().hide(fragments.get(0)).hide(fragments.get(1)).hide(fragments.get(2)).hide(fragments.get(3)).hide(fragments.get(4)).show(fragments.get(0)).commit();
                subscriptText.setTextColor(getResources().getColor(R.color.no_selected));
                activityText.setTextColor(getResources().getColor(R.color.no_selected));
                searchText.setTextColor(getResources().getColor(R.color.no_selected));
                accountText.setTextColor(getResources().getColor(R.color.no_selected));
                homeText.setTextColor(getResources().getColor(R.color.selected));

//                subscriptImage.setImageDrawable(getResources().getDrawable(R.mipmap.subscript_no_selected));
//                activityImage.setImageDrawable(getResources().getDrawable(R.mipmap.activity_no_selected));
//                searchImage.setImageDrawable(getResources().getDrawable(R.mipmap.search_no_selected));
//                accountImage.setImageDrawable(getResources().getDrawable(R.mipmap.account_no_selected));
//                homeImage.setImageDrawable(getResources().getDrawable(R.mipmap.home_selected));
            }
        });

        subscriptLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragmentManager.beginTransaction().hide(fragments.get(0)).hide(fragments.get(1)).hide(fragments.get(2)).hide(fragments.get(3)).hide(fragments.get(4)).show(fragments.get(1)).commit();
                homeText.setTextColor(getResources().getColor(R.color.no_selected));
                activityText.setTextColor(getResources().getColor(R.color.no_selected));
                searchText.setTextColor(getResources().getColor(R.color.no_selected));
                accountText.setTextColor(getResources().getColor(R.color.no_selected));
                subscriptText.setTextColor(getResources().getColor(R.color.selected));

//                homeImage.setImageDrawable(getResources().getDrawable(R.mipmap.home_no_selected));
//                activityImage.setImageDrawable(getResources().getDrawable(R.mipmap.activity_no_selected));
//                searchImage.setImageDrawable(getResources().getDrawable(R.mipmap.search_no_selected));
//                accountImage.setImageDrawable(getResources().getDrawable(R.mipmap.account_no_selected));
//                subscriptImage.setImageDrawable(getResources().getDrawable(R.mipmap.subscript_selected));
            }
        });

        activityLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragmentManager.beginTransaction().hide(fragments.get(0)).hide(fragments.get(1)).hide(fragments.get(2)).hide(fragments.get(3)).hide(fragments.get(4)).show(fragments.get(2)).commit();

                subscriptText.setTextColor(getResources().getColor(R.color.no_selected));
                homeText.setTextColor(getResources().getColor(R.color.no_selected));
                searchText.setTextColor(getResources().getColor(R.color.no_selected));
                accountText.setTextColor(getResources().getColor(R.color.no_selected));
                activityText.setTextColor(getResources().getColor(R.color.selected));

//                subscriptImage.setImageDrawable(getResources().getDrawable(R.mipmap.subscript_no_selected));
//                homeImage.setImageDrawable(getResources().getDrawable(R.mipmap.home_no_selected));
//                searchImage.setImageDrawable(getResources().getDrawable(R.mipmap.search_no_selected));
//                accountImage.setImageDrawable(getResources().getDrawable(R.mipmap.account_no_selected));
//                activityImage.setImageDrawable(getResources().getDrawable(R.mipmap.activity_selected));

            }
        });

        searchLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragmentManager.beginTransaction().hide(fragments.get(0)).hide(fragments.get(1)).hide(fragments.get(2)).hide(fragments.get(3)).hide(fragments.get(4)).show(fragments.get(3)).commit();

                subscriptText.setTextColor(getResources().getColor(R.color.no_selected));
                activityText.setTextColor(getResources().getColor(R.color.no_selected));
                homeText.setTextColor(getResources().getColor(R.color.no_selected));
                accountText.setTextColor(getResources().getColor(R.color.no_selected));
                searchText.setTextColor(getResources().getColor(R.color.selected));

//                subscriptImage.setImageDrawable(getResources().getDrawable(R.mipmap.subscript_no_selected));
//                activityImage.setImageDrawable(getResources().getDrawable(R.mipmap.activity_no_selected));
//                homeImage.setImageDrawable(getResources().getDrawable(R.mipmap.home_no_selected));
//                accountImage.setImageDrawable(getResources().getDrawable(R.mipmap.account_no_selected));
//                searchImage.setImageDrawable(getResources().getDrawable(R.mipmap.search_selected));

            }
        });

        accountLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fragmentManager.beginTransaction().hide(fragments.get(0)).hide(fragments.get(1)).hide(fragments.get(2)).hide(fragments.get(3)).hide(fragments.get(4)).show(fragments.get(4)).commit();

                subscriptText.setTextColor(getResources().getColor(R.color.no_selected));
                activityText.setTextColor(getResources().getColor(R.color.no_selected));
                searchText.setTextColor(getResources().getColor(R.color.no_selected));
                homeText.setTextColor(getResources().getColor(R.color.no_selected));
                accountText.setTextColor(getResources().getColor(R.color.selected));

//                subscriptImage.setImageDrawable(getResources().getDrawable(R.mipmap.subscript_no_selected));
//                activityImage.setImageDrawable(getResources().getDrawable(R.mipmap.activity_no_selected));
//                searchImage.setImageDrawable(getResources().getDrawable(R.mipmap.searche_no_selected));
//                homeImage.setImageDrawable(getResources().getDrawable(R.mipmap.home_no_selected));
//                accountImage.setImageDrawable(getResources().getDrawable(R.mipmap.account_selected));
            }
        });
    }
}
